Skip to content

Wake sleeping backends with an isolated browser document request - #124

Merged
xrpbanks merged 1 commit into
mainfrom
fix/login-document-warmup
Sep 6, 2026
Merged

Wake sleeping backends with an isolated browser document request#124
xrpbanks merged 1 commit into
mainfrom
fix/login-document-warmup

Conversation

@xrpbanks

@xrpbanks xrpbanks commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Login succeeds while the backend is running, then stalls before Xaman after the backend becomes idle. On 2026-09-06 the backend stopped at 14:50:26; background warmup requests did not restart it. A user subsequently opened its public health URL in the same browser, saw Render's loading page, and received the expected health JSON.

This change adds one hidden, fully sandboxed document request to the configured HTTPS Render health URL during warmup. It reproduces a browser document request without leaving the original login tab. Existing health probes must still confirm the expected JSON; the document's load event does not establish readiness. Retry-After handling and the 180-second overall deadline remain in place. The document is removed on success, cancellation or timeout.

The URL guard excludes credentials, arbitrary origins, non-HTTPS URLs, ports, paths, queries and fragments. The frame has no sandbox permissions and sends no referrer. Backend framing protections remain intact.

Validation: 36 focused warmup, login and logout tests pass; Next.js production build, lint and type checks pass. The new tests cover simulated document-dependent startup, timeout, cancellation, and URL restrictions. Only two files change.

Evidence limit: a top-level navigation has been observed live; an embedded document request still needs a real cold-start acceptance check. This PR does not claim the production incident is resolved. Existing frontend release ffa4178 is the rollback reference.

A user navigation successfully woke the backend after background health requests had timed out. Request one isolated health document during warmup, and retain the existing JSON readiness and retry checks.

Restrict the document to a configured HTTPS Render origin and remove it on success, timeout or cancellation. Tests and production build pass; a real cold-start check remains required.
@xrpbanks
xrpbanks marked this pull request as ready for review September 6, 2026 13:17
Copilot AI lite review requested due to automatic review settings September 6, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is tightly scoped, has explicit safety/URL guardrails and deterministic cleanup, and is covered by targeted tests for wake behavior, timeout, cancellation, and restrictions.

Pull request overview

Adds a browser-only, fully sandboxed hidden document request (iframe) to help wake a sleeping Render backend during warmup without navigating away from the current tab, while still requiring the existing JSON health probes to determine readiness.

Changes:

  • Introduce mountBackendWakeDocument() to mount and reliably remove a hidden sandboxed iframe targeting ${backend.origin}/health when the configured base URL is a strict HTTPS *.onrender.com origin.
  • Wire the mount/remove lifecycle into waitForBackendReady() so cleanup happens on success, timeout, or cancellation.
  • Expand warmup tests to cover document-dependent wake behavior, timeout/cancellation cleanup, and URL restriction cases (with a VM-injected browser/document).
File summaries
File Description
tools/tests/backend_warmup_rate_limit.test.mjs Extends the warmup harness to inject URL/browser globals and adds focused tests for the new iframe-based wake behavior and URL guardrails.
frontend/lib/backendRequest.ts Adds a guarded hidden sandboxed iframe “wake” request during backend warmup, with guaranteed cleanup in finally.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@xrpbanks
xrpbanks merged commit 40092e6 into main Sep 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants